package me.atbar.moonlib.builder;

import lombok.Getter;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

/**
 * @author Administrator
 */
public class InventoryBuilder {

    @Getter
    private final String title;
    @Getter
    private final int size;
    @Getter
    private final Inventory inventory;

    /**
     * 只有一个容器标题
     *
     * @param title 容器标题
     */
    public InventoryBuilder(@NonNull String title, int size) {
        this.title = title;
        this.size = size;
        this.inventory = Bukkit.createInventory(null, size, title);
    }

    public InventoryBuilder(@NonNull String title, int size, InventoryHolder holder) {
        this.title = title;
        this.size = size;
        this.inventory = Bukkit.createInventory(holder, size, title);
    }

    public InventoryBuilder put(int slot, ItemStack item) {
        inventory.setItem(slot, item);
        return this;
    }

    public InventoryBuilder remove(ItemStack item) {
        inventory.remove(item);
        return this;
    }

    public Inventory build() {
        return inventory;
    }

}
